package pkg_member

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/pkg_member"
	pkg_memberReq "github.com/flipped-aurora/gin-vue-admin/server/model/pkg_member/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type JoinactivateApi struct {
}

var joinactivateService = service.ServiceGroupApp.Pkg_memberServiceGroup.JoinactivateService

// CreateJoinactivate 创建参加活动
// @Tags Joinactivate
// @Summary 创建参加活动
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body pkg_member.Joinactivate true "创建参加活动"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /joinactivate/createJoinactivate [post]
func (joinactivateApi *JoinactivateApi) CreateJoinactivate(c *gin.Context) {
	var joinactivate pkg_member.Joinactivate
	err := c.ShouldBindJSON(&joinactivate)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := joinactivateService.CreateJoinactivate(&joinactivate); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteJoinactivate 删除参加活动
// @Tags Joinactivate
// @Summary 删除参加活动
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body pkg_member.Joinactivate true "删除参加活动"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /joinactivate/deleteJoinactivate [delete]
func (joinactivateApi *JoinactivateApi) DeleteJoinactivate(c *gin.Context) {
	ID := c.Query("ID")
	if err := joinactivateService.DeleteJoinactivate(ID); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteJoinactivateByIds 批量删除参加活动
// @Tags Joinactivate
// @Summary 批量删除参加活动
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /joinactivate/deleteJoinactivateByIds [delete]
func (joinactivateApi *JoinactivateApi) DeleteJoinactivateByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	if err := joinactivateService.DeleteJoinactivateByIds(IDs); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateJoinactivate 更新参加活动
// @Tags Joinactivate
// @Summary 更新参加活动
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body pkg_member.Joinactivate true "更新参加活动"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /joinactivate/updateJoinactivate [put]
func (joinactivateApi *JoinactivateApi) UpdateJoinactivate(c *gin.Context) {
	var joinactivate pkg_member.Joinactivate
	err := c.ShouldBindJSON(&joinactivate)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	//joinactivate.UpdatedBy = utils.GetUserID(c)

	if err := joinactivateService.UpdateJoinactivate(joinactivate); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindJoinactivate 用id查询参加活动
// @Tags Joinactivate
// @Summary 用id查询参加活动
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query pkg_member.Joinactivate true "用id查询参加活动"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /joinactivate/findJoinactivate [get]
func (joinactivateApi *JoinactivateApi) FindJoinactivate(c *gin.Context) {
	ID := c.Query("ID")
	if rejoinactivate, err := joinactivateService.GetJoinactivate(ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"rejoinactivate": rejoinactivate}, c)
	}
}

// GetJoinactivateList 分页获取参加活动列表
// @Tags Joinactivate
// @Summary 分页获取参加活动列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query pkg_memberReq.JoinactivateSearch true "分页获取参加活动列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /joinactivate/getJoinactivateList [get]
func (joinactivateApi *JoinactivateApi) GetJoinactivateList(c *gin.Context) {
	var pageInfo pkg_memberReq.JoinactivateSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := joinactivateService.GetJoinactivateInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetJoinactivatePublic 不需要鉴权的参加活动接口
// @Tags Joinactivate
// @Summary 不需要鉴权的参加活动接口
// @accept application/json
// @Produce application/json
// @Param data query pkg_memberReq.JoinactivateSearch true "分页获取参加活动列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /joinactivate/getJoinactivateList [get]
func (joinactivateApi *JoinactivateApi) GetJoinactivatePublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的参加活动接口信息",
	}, "获取成功", c)
}
